From 193a95a2677731e425da4784e89ccf679fb458f4 Mon Sep 17 00:00:00 2001 From: Romain Sertelon Date: Wed, 10 May 2017 23:30:32 +0200 Subject: [PATCH] Apply --all if workspace is virtual Should help close #4021 --- src/bin/bench.rs | 22 ++++++++++++++++------ src/bin/build.rs | 12 ++++++++---- src/bin/check.rs | 10 +++++++--- src/bin/doc.rs | 9 +++++++-- src/bin/test.rs | 17 +++++++++++++---- src/cargo/core/workspace.rs | 7 +++++++ 6 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/bin/bench.rs b/src/bin/bench.rs index ff1e0b4e7..31004a2d4 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -1,3 +1,5 @@ +use std::env; + use cargo::core::Workspace; use cargo::ops::{self, MessageFormat, Packages}; use cargo::util::{CliResult, CliError, Config, CargoErrorKind}; @@ -88,17 +90,26 @@ Compilation can be customized with the `bench` profile in the manifest. "; pub fn execute(options: Options, config: &Config) -> CliResult { - let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; - - let spec = Packages::from_flags(options.flag_all, - &options.flag_exclude, - &options.flag_package)?; + debug!("executing; cmd=cargo-bench; args={:?}", + env::args().collect::>()); config.configure(options.flag_verbose, options.flag_quiet, &options.flag_color, options.flag_frozen, options.flag_locked)?; + + let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; + let ws = Workspace::new(&root, config)?; + + let spec = if options.flag_all || ws.is_virtual() { + Packages::All + } else { + Packages::from_flags(options.flag_all, + &options.flag_exclude, + &options.flag_package)? + }; + let ops = ops::TestOptions { no_run: options.flag_no_run, no_fail_fast: options.flag_no_fail_fast, @@ -124,7 +135,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult { }, }; - let ws = Workspace::new(&root, config)?; let err = ops::run_benches(&ws, &ops, &options.arg_args)?; match err { None => Ok(()), diff --git a/src/bin/build.rs b/src/bin/build.rs index c679fc50f..9f0757aa3 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -92,10 +92,15 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_locked)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; + let ws = Workspace::new(&root, config)?; - let spec = Packages::from_flags(options.flag_all, - &options.flag_exclude, - &options.flag_package)?; + let spec = if options.flag_all || ws.is_virtual() { + Packages::All + } else { + Packages::from_flags(options.flag_all, + &options.flag_exclude, + &options.flag_package)? + }; let opts = CompileOptions { config: config, @@ -117,7 +122,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult { target_rustc_args: None, }; - let ws = Workspace::new(&root, config)?; ops::compile(&ws, &opts)?; Ok(()) } diff --git a/src/bin/check.rs b/src/bin/check.rs index fd36f5420..03c15e624 100644 --- a/src/bin/check.rs +++ b/src/bin/check.rs @@ -91,9 +91,13 @@ pub fn execute(options: Options, config: &Config) -> CliResult { let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; - let spec = Packages::from_flags(options.flag_all, - &options.flag_exclude, - &options.flag_package)?; + let spec = if options.flag_all || ws.is_virtual() { + Packages::All + } else { + Packages::from_flags(options.flag_all, + &options.flag_exclude, + &options.flag_package)? + }; let opts = CompileOptions { config: config, diff --git a/src/bin/doc.rs b/src/bin/doc.rs index 6b4190985..cfa1116d8 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -1,3 +1,5 @@ +use std::env; + use cargo::core::Workspace; use cargo::ops::{self, MessageFormat, Packages}; use cargo::util::{CliResult, Config}; @@ -69,6 +71,9 @@ the `cargo help pkgid` command. "; pub fn execute(options: Options, config: &Config) -> CliResult { + debug!("executing; cmd=cargo-check; args={:?}", + env::args().collect::>()); + config.configure(options.flag_verbose, options.flag_quiet, &options.flag_color, @@ -76,8 +81,9 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_locked)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; + let ws = Workspace::new(&root, config)?; - let spec = if options.flag_all { + let spec = if options.flag_all || ws.is_virtual() { Packages::All } else { Packages::Packages(&options.flag_package) @@ -109,7 +115,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult { }, }; - let ws = Workspace::new(&root, config)?; ops::doc(&ws, &doc_opts)?; Ok(()) } diff --git a/src/bin/test.rs b/src/bin/test.rs index fe8d5757f..daef1e472 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -1,3 +1,5 @@ +use std::env; + use cargo::core::Workspace; use cargo::ops::{self, MessageFormat, Packages}; use cargo::util::{CliResult, CliError, Config, CargoErrorKind}; @@ -109,6 +111,9 @@ To get the list of all options available for the test binaries use this: "; pub fn execute(options: Options, config: &Config) -> CliResult { + debug!("executing; cmd=cargo-test; args={:?}", + env::args().collect::>()); + config.configure(options.flag_verbose, options.flag_quiet, &options.flag_color, @@ -116,6 +121,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_locked)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; + let ws = Workspace::new(&root, config)?; let empty = Vec::new(); let (mode, filter); @@ -132,9 +138,13 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &options.flag_bench, options.flag_benches); } - let spec = Packages::from_flags(options.flag_all, - &options.flag_exclude, - &options.flag_package)?; + let spec = if options.flag_all || ws.is_virtual() { + Packages::All + } else { + Packages::from_flags(options.flag_all, + &options.flag_exclude, + &options.flag_package)? + }; let ops = ops::TestOptions { no_run: options.flag_no_run, @@ -157,7 +167,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult { }, }; - let ws = Workspace::new(&root, config)?; let err = ops::run_tests(&ws, &ops, &options.arg_args)?; match err { None => Ok(()), diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 5f93baa85..ad53fc5b5 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -179,6 +179,13 @@ impl<'cfg> Workspace<'cfg> { } } + pub fn is_virtual(&self) -> bool { + match *self.packages.get(&self.current_manifest) { + MaybePackage::Package(..) => false, + MaybePackage::Virtual(..) => true + } + } + /// Returns the `Config` this workspace is associated with. pub fn config(&self) -> &'cfg Config { self.config -- 2.30.2